//
//  BumenView.m
//  文印室
//
//  Created by KL on 17/2/22.
//  Copyright © 2017年 KM. All rights reserved.
//

#import "BumenView.h"
#import "DataChe.h"
#import "BmData.h"
#import "AddBumViewController.h"
@interface BumenView ()
{
    NSMutableArray<BmItemData *>*data;
}
@end

@implementation BumenView

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"部门列表";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addBum:)];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    data = [NSMutableArray new];
    [DataChe getWithParam:@"http://a.xl18z.cn/api/department/list" complete:^(NSDictionary *d) {
        NSLog(@"正在阅读部门列表.");
        BmData *bd = [[BmData alloc]initWithDictionary:d];
        [data addObjectsFromArray:bd.record];
        NSLog(@"%@",data);
        [self.tableView reloadData];
    }];
}

- (void)addBum:(id)sender
{
    AddBumViewController *add = [self.storyboard instantiateViewControllerWithIdentifier:@"addbm"];
    [self.navigationController pushViewController:add animated:YES];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    BmItemData *b = data[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",b.id];
    cell.detailTextLabel.text = b.name;
    cell.detailTextLabel.textColor = [UIColor blueColor];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
